--Initializing IP address generator

local tArgs = {...}
if #tArgs < 4 then
 gui.printAppInfo("nmap", "no IP address specified")
else
 gui.printAppSuccess("nmap", "scanning for specified IP")
end

if #tArgs == 5 then
 gui.printAppSuccess("nmap", "specified DNS record")
end

local ip, node

if #tArgs < 4 then
 local x = tostring(math.random(0, 255))
 local y = tostring(math.random(0, 255))
 local z = tostring(math.random(0, 255))
 local r = tostring(math.random(0, 255))
 ip = x.."."..y.."."..z.."."..r
elseif #tArgs >= 4 then
 ip = tArgs[1].."."..tArgs[2].."."..tArgs[3].."."..tArgs[4]
end

if not fs.exists("/network") or not fs.isDir("/network") then
 fs.makeDir("/network")
end

--node = "/network/"..ip

gui.printAppInfo("nmap", "found "..ip)

if #tArgs == 5 then
 gui.printAppSuccess("nmap", "assigned DNS record "..tArgs[5])
 node = "/network/"..tArgs[5]
else
 gui.printAppWarning("nmap", "no DNS record found, defaulting to IP")
 node = "/network/"..ip
end

if fs.exists(node) and fs.isDir(node) then
 gui.printAppInfo("nmap", ip.." already known")
else
 fs.makeDir(node)
 fs.makeDir(node.."/sys")
 fs.makeDir(node.."/home")
 fs.makeDir(node.."/bin")
 gui.printAppSuccess("nmap", ip.." added to network")
end